package com.hj.api;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.google.gson.Gson;
import com.hj.api.bean.SQDataBean;
import com.hj.api.bean.SQPostBean;
import com.hj.api.bean.TokenBean;
import com.hj.api.constant.URL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

import static com.hj.api.util.Constant.developerId;
import static com.hj.api.util.Constant.developerKey;

public class TimedTask {


    private static TokenBean tokenBean;
    public static SQPostBean sqPostBean = new SQPostBean("admin","111111");
    private static SQDataBean sqDataBean;
    Gson gson = new Gson();



    /**
     * 业务逻辑处理
     */
    public void execute() {


        HashMap<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("developerId", developerId);
        paramMap.put("developerKey", developerKey);
        String result3= HttpUtil.get(URL.getToken, paramMap);
        TokenBean data = gson.fromJson(result3, TokenBean.class);
        TimedTask.setTokenBean(data);

        String res = HttpRequest.post(URL.sq)
                .header("Content-type","application/json")
                .body(gson.toJson(TimedTask.sqPostBean))
                .execute()
                .body();;
        SQDataBean sqDataBean = gson.fromJson(res, SQDataBean.class);
        TimedTask.setSqDataBean(sqDataBean);
    }

    public static TokenBean getTokenBean() {
        return tokenBean;
    }

    public static void setTokenBean(TokenBean tokenBean) {
        TimedTask.tokenBean = tokenBean;
        Gson gson = new Gson();
        String token = gson.toJson(tokenBean);
        System.out.println(token);
     }


    public static SQDataBean getSqDataBean() {
        return sqDataBean;
    }

    public static void setSqDataBean(SQDataBean sqDataBean) {
        TimedTask.sqDataBean = sqDataBean;
    }
}
